﻿using System;
using System.IO;

namespace WangCon
{

    public class DataSave
    {

        private static string pathExe = AppDomain.CurrentDomain.BaseDirectory;

        private string path = pathExe + "\\Data\\";
        private string file = "Test";
        private string head = "W1,W2,W3";

        //System.IO.Path.Combine(pathExe, "Data\\");

        public DataSave()
        {
            
        }
        
        public DataSave(string path ,string file, string head)
        {
            this.path = path;
            this.file = file;
            this.head = head;

            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
                string fileFullName = System.IO.Path.Combine(path
                    , string.Format(DateTime.Now.ToString("yy-MM-dd-") + file +".csv"));

                using (StreamWriter output = System.IO.File.AppendText(fileFullName))
                {
                    output.WriteLine(DateTime.Now.ToString("         ,") + head);
                    output.Close();
                }

            }

        }
        
        public void WriteData(string text)
        {
     
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }

            //string fileFullName = System.IO.Path.Combine(path
            //  , string.Format("{0}.log", DateTime.Now.ToString("yyyy-MM-dd-HH:mm:ss")));
            //yyyy-MM-dd HH:mm:ss.fff

            string fileFullName = System.IO.Path.Combine(path
              , string.Format(DateTime.Now.ToString("yy-MM-dd-") + file + ".csv"));

            using (StreamWriter output = System.IO.File.AppendText(fileFullName))
            {
                output.WriteLine(DateTime.Now.ToString("yyyy-MM-dd-HH:mm:ss:fff,") + text);
                output.Close();
            }

        }

    }

}
